﻿@{
    ViewBag.Title = "FileForm";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<link href="~/Content/scripts/plugins/uploadify/uploadify.css" rel="stylesheet" />
<link href="~/Content/scripts/plugins/uploadify/uploadify.extension.css" rel="stylesheet" />
<script src="~/Content/scripts/plugins/uploadify/jquery.uploadify.min.js"></script>
<script>
    var keyValue = request('keyValue');
    var BillCode = request('BillCode');
    var RuleCode = request('RuleCode');
    var type = request('type');
    var _IsSubmit = 0;
    var _IsUpload = 0;
    $(function () {
        //获取表单
        if (!!keyValue) {            
            var rowdata = top.Form.$("#gridtable1").jqGridRow()[0];
            $("#form1").SetWebControls(rowdata);
            if (!rowdata.ReceiveUserName)
                $("#ReceiveUserName").val("@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserName");
            if (!rowdata.ReceiveDate)
                $("#ReceiveDate").val("@DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")");
            $("#FileName").val("@ViewBag.FileName");
            _IsSubmit = rowdata.IsSubmit.substring(23, 25) == "on" ? "1" : "0";
            if (_IsSubmit == 1 && type == 1) $("#CommitState").attr("checked", true);
            else if (rowdata.CommitState.substring(10, 12) == "fa") { $("#CommitState").attr("checked", true); }
            _IsUpload = rowdata.IsUpload.substring(23, 25) == "on" ? "1" : "0";
        }

        //图片上传插件
        $('#File').uploadify({
            //是否自动上传
            'auto': false,
            //超时时间
            'successTimeout': 99999,
            //上传文件的大小限制
            'fileSizeLimit': '2GB',
            'queueSizeLimit': 5,
            'uploader': 'SaveFile',
            'swf': '@Url.Content("~/Content/scripts/plugins/uploadify/uploadify.swf")',
            'buttonText': '点击选择文件',
            //上传文件选择按钮的高度
            'height': 30,
            //上传文件选择按钮的宽度
            'width': 120,
            'multi': false,
            //文件选择后的容器ID
            'queueID': 'queue',
            //在浏览窗口底部的文件类型下拉菜单中显示的文本
            'fileTypeDesc': '支持的格式：',
            //允许上传的文件后缀
            'fileTypeExts': '*.*',
            'onSelectError': function (file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        alert("上传的文件数量已经超出系统限制的" + jQuery('#File').uploadify('settings', 'queueSizeLimit') + "个文件！");
                        break;
                    case -110:
                        alert("文件 [" + file.name + "] 大小超出系统限制的" + jQuery('#File').uploadify('settings', 'fileSizeLimit') + "大小！");
                        break;
                    case -120:
                        alert("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        alert("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            },
            'onClearQueue': function (queueItemCount) {
                return;
            },
            'onQueueComplete': function (queueData) {
                return;
            },
            'onUploadSuccess': function (file, data, response) {
                var postData = $("#form1").GetWebControls(keyValue);
                var $gridTable = top.Form.$("#gridtable1");
                var rowdata = top.Form.$("#gridtable1").jqGridRow()[0];
                if (type == 1) {
                    postData["CommitState"] = 1;
                    postData["IsQualified"] = 0;
                }
                else {
                    postData["CreateUserName"] = rowdata.CreateUserName;
                    postData["CommitState"] = 1;
                    postData["IsQualified"] = 0;
                }
                postData["FileUrl"] = data;
                postData["RuleCode"] = rowdata.RuleCode;
                $gridTable.setRowData(keyValue, postData);
                dialogMsg("操作成功。", 1);
                dialogClose();
            },
            'onSelect': function (fileObj) {
                $("#Url").text(fileObj.name);
            }
        });

    })
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        if ($("#Url").text() != "") {
            jQuery('#File').uploadify('upload', '*');
        } else {
            var postData = $("#form1").GetWebControls(keyValue);          
            var $gridTable = top.Form.$("#gridtable1");
            var rowdata = top.Form.$("#gridtable1").jqGridRow()[0];
            if (type == 1) {
                postData["IsQualified"] = -1;
            } else {
                postData["CreateUserName"] = rowdata.CreateUserName;
                postData["FileUrl"] = rowdata.FileUrl;
                if (rowdata.FileUrl != null && rowdata.FileUrl != "") {
                    postData["IsQualified"] = 0;
                } else { postData["IsQualified"] = -1; }
            }
            
            if ($("#CommitState").is(":checked")) {
                postData["CommitState"] = 1;
            }
            else  if (rowdata.FileUrl != null && rowdata.FileUrl != "") { postData["CommitState"] = 1; }
            else { postData["CommitState"] = 0; }
            postData["RuleCode"] = rowdata.RuleCode;           
            postData["FileName"] = $("#Url").text();
            $gridTable.setRowData(keyValue, postData);
            dialogMsg("操作成功。", 1);
            dialogClose();
        }       
    }
</script>
<div style="margin-left: 10px; margin-right: 10px;padding-top:10px;">

    <table class="form">
        <tr>
            <td class="formTitle">资料名称<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="FileName" value="" readonly type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">提交文件<font face="宋体">*</font></td>
            <td class="formValue">
                <input type="checkbox" id="CommitState" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">上传文件<font face="宋体">*</font></td>
            <td class="formValue">
                <input type="file" id="File" name="File" /><span id="Url" style="height:30px;line-height:30px;margin-left:5px;"></span>
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;line-height:50px;">
                备注
            </th>
            <td class="formValue">
                <textarea id="Memo" class="form-control" style="height: 50px;"></textarea>
            </td>
        </tr>
        <tr>
            <td class="formTitle">接收人</td>
            <td class="formValue">
                <input id="ReceiveUserName" readonly value="" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">接收时间</td>
            <td class="formValue">
                <input id="ReceiveDate" readonly type="text" class="form-control input-wdatepicker" value="" @*placeholder="请输入提交时间" onfocus="WdatePicker()"*@ />
            </td>
        </tr>

    </table>
</div>